sources = files(
  'FingerprintProtocol.pb-c.c',
  'LocalStorageProtocol.pb-c.c',
  'WhisperTextProtocol.pb-c.c',
  'curve.c',
  'curve25519/curve25519-donna.c',
  'curve25519/ed25519/additions/compare.c',
  'curve25519/ed25519/additions/curve_sigs.c',
  'curve25519/ed25519/additions/elligator.c',
  'curve25519/ed25519/additions/fe_isequal.c',
  'curve25519/ed25519/additions/fe_isreduced.c',
  'curve25519/ed25519/additions/fe_mont_rhs.c',
  'curve25519/ed25519/additions/fe_montx_to_edy.c',
  'curve25519/ed25519/additions/fe_sqrt.c',
  'curve25519/ed25519/additions/ge_isneutral.c',
  'curve25519/ed25519/additions/ge_montx_to_p3.c',
  'curve25519/ed25519/additions/ge_neg.c',
  'curve25519/ed25519/additions/ge_p3_to_montx.c',
  'curve25519/ed25519/additions/ge_scalarmult.c',
  'curve25519/ed25519/additions/ge_scalarmult_cofactor.c',
  'curve25519/ed25519/additions/generalized/ge_p3_add.c',
  'curve25519/ed25519/additions/generalized/gen_eddsa.c',
  'curve25519/ed25519/additions/generalized/gen_labelset.c',
  'curve25519/ed25519/additions/generalized/gen_veddsa.c',
  'curve25519/ed25519/additions/generalized/gen_x.c',
  'curve25519/ed25519/additions/generalized/point_isreduced.c',
  'curve25519/ed25519/additions/generalized/sc_isreduced.c',
  'curve25519/ed25519/additions/keygen.c',
  'curve25519/ed25519/additions/open_modified.c',
  'curve25519/ed25519/additions/sc_clamp.c',
  'curve25519/ed25519/additions/sc_cmov.c',
  'curve25519/ed25519/additions/sc_neg.c',
  'curve25519/ed25519/additions/sign_modified.c',
  'curve25519/ed25519/additions/utility.c',
  'curve25519/ed25519/additions/xeddsa.c',
  'curve25519/ed25519/additions/zeroize.c',
  'curve25519/ed25519/fe_0.c',
  'curve25519/ed25519/fe_1.c',
  'curve25519/ed25519/fe_add.c',
  'curve25519/ed25519/fe_cmov.c',
  'curve25519/ed25519/fe_copy.c',
  'curve25519/ed25519/fe_frombytes.c',
  'curve25519/ed25519/fe_invert.c',
  'curve25519/ed25519/fe_isnegative.c',
  'curve25519/ed25519/fe_isnonzero.c',
  'curve25519/ed25519/fe_mul.c',
  'curve25519/ed25519/fe_neg.c',
  'curve25519/ed25519/fe_pow22523.c',
  'curve25519/ed25519/fe_sq.c',
  'curve25519/ed25519/fe_sq2.c',
  'curve25519/ed25519/fe_sub.c',
  'curve25519/ed25519/fe_tobytes.c',
  'curve25519/ed25519/ge_add.c',
  'curve25519/ed25519/ge_double_scalarmult.c',
  'curve25519/ed25519/ge_frombytes.c',
  'curve25519/ed25519/ge_madd.c',
  'curve25519/ed25519/ge_msub.c',
  'curve25519/ed25519/ge_p1p1_to_p2.c',
  'curve25519/ed25519/ge_p1p1_to_p3.c',
  'curve25519/ed25519/ge_p2_0.c',
  'curve25519/ed25519/ge_p2_dbl.c',
  'curve25519/ed25519/ge_p3_0.c',
  'curve25519/ed25519/ge_p3_dbl.c',
  'curve25519/ed25519/ge_p3_to_cached.c',
  'curve25519/ed25519/ge_p3_to_p2.c',
  'curve25519/ed25519/ge_p3_tobytes.c',
  'curve25519/ed25519/ge_precomp_0.c',
  'curve25519/ed25519/ge_scalarmult_base.c',
  'curve25519/ed25519/ge_sub.c',
  'curve25519/ed25519/ge_tobytes.c',
  'curve25519/ed25519/nacl_sha512/blocks.c',
  'curve25519/ed25519/nacl_sha512/hash.c',
  'curve25519/ed25519/open.c',
  'curve25519/ed25519/sc_muladd.c',
  'curve25519/ed25519/sc_reduce.c',
  'curve25519/ed25519/sign.c',
  'curve25519/ed25519/tests/internal_fast_tests.c',
  'curve25519/ed25519/tests/internal_slow_tests.c',
  'device_consistency.c',
  'fingerprint.c',
  'group_cipher.c',
  'group_session_builder.c',
  'hkdf.c',
  'key_helper.c',
  'protobuf-c/protobuf-c.c',
  'protocol.c',
  'ratchet.c',
  'sender_key.c',
  'sender_key_record.c',
  'sender_key_state.c',
  'session_builder.c',
  'session_cipher.c',
  'session_pre_key.c',
  'session_record.c',
  'session_state.c',
  'signal_protocol.c',
  'vpool.c',
)
include_directories = include_directories(
  '.',
  'curve25519',
  'curve25519/ed25519',
  'curve25519/ed25519/additions',
  'curve25519/ed25519/additions/generalized',
  'curve25519/ed25519/nacl_includes',
  'curve25519/ed25519/tests',
)
c_args = []
public_c_args = []
if cc.has_function(
  'SecureZeroMemory',
  prefix: '#include <Windows.h>',
)
  c_args += ['-DSECUREZEROMEMORY']
endif
if cc.has_function(
  'memset_s',
  prefix: '#include <string.h>',
)
  c_args += ['-DHAVE_MEMSET_S']
endif
if host_machine.system() == 'windows'
  public_c_args += ['-D_WINDOWS']
endif

libsignal_protocol_c = library(
  'signal-protocol-c',
  sources,
  c_args: c_args + public_c_args,
  include_directories: include_directories,
  dependencies: [
    cc.find_library(
      'm',
      required: false,
    ),
  ],
  vs_module_defs: 'signal-protocol-c.def',
  install: true,
  version: meson.project_version(),
)
import('pkgconfig').generate(
  libsignal_protocol_c,
  name: 'libsignal-protocol-c',
  description: 'Signal Protocol C Library',
  extra_cflags: public_c_args,
)
libsignal_protocol_c_dep = declare_dependency(
  include_directories: include_directories,
  link_with: libsignal_protocol_c,
  compile_args: public_c_args,
)
meson.override_dependency('libsignal-protocol-c', libsignal_protocol_c_dep)
